// lib/components/common_header.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CommonHeaderItem {
  String name;
  String route;
  CommonHeaderItem(this.name, this.route);
}

class CommonHeader extends StatelessWidget {
  final String title;
  final List<Map<String, String>> navItems;
  final String currentRoute;

  const CommonHeader({
    super.key,
    required this.title,
    required this.navItems,
    required this.currentRoute,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFF1e5799), Color(0xFF207cca)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 5,
            spreadRadius: 2,
            offset: Offset(0, 3),
          ),
        ],
      ),
      padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                title,
                style: const TextStyle(
                  color: Colors.white,
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                ),
              ),
              // 移动端使用抽屉菜单，桌面端使用水平导航
              if (MediaQuery.of(context).size.width < 768)
                IconButton(
                  icon: const Icon(Icons.menu, color: Colors.white),
                  onPressed: () => _openDrawer(context),
                )
              else
                Row(
                  children: navItems
                      .map((item) => Padding(
                            padding: const EdgeInsets.only(left: 25),
                            child: InkWell(
                              onTap: () =>
                                  Navigator.pushNamed(context, item['route']!),
                              child: Text(
                                item['name']!,
                                style: TextStyle(
                                  color: currentRoute == item['route']
                                      ? Colors.white70
                                      : Colors.white,
                                  fontSize: 16,
                                ),
                              ),
                            ),
                          ))
                      .toList(),
                ),
            ],
          ),
        ],
      ),
    );
  }

  void _openDrawer(BuildContext context) {
    showModalBottomSheet(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(10)),
      ),
      builder: (context) => Container(
        padding: const EdgeInsets.all(20),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: navItems
              .map((item) => ListTile(
                    title: Text(item['name']!),
                    onTap: () {
                      Navigator.pop(context);
                      Navigator.pushNamed(context, item['route']!);
                    },
                  ))
              .toList(),
        ),
      ),
    );
  }
}

// lib/components/breadcrumb.dart

class Breadcrumb extends StatelessWidget {
  final String text;

  const Breadcrumb({super.key, required this.text});

  @override
  Widget build(BuildContext context) {
    return _buildBreadcrumb();
  }

  // 面包屑
  Widget _buildBreadcrumb() {
    return Padding(
      padding: EdgeInsets.only(left: 15, right: 15, bottom: 40),
      child: Text(
        text,
        style: TextStyle(
          color: const Color(0xFF666666),
          fontSize: 14,
        ),
      ),
    );
  }
}

// lib/components/page_title.dart

class PageTitle extends StatelessWidget {
  final String title;
  final String subtitle;

  const PageTitle({
    super.key,
    required this.title,
    required this.subtitle,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        // 页面标题
        Center(
          child: Column(
            children: [
              Text(
                title,
                style: TextStyle(
                  color: Color(0xFF1E5799),
                  fontSize: 32,
                  fontWeight: FontWeight.bold,
                  height: 1.6,
                ),
              ),
              Container(
                width: 100,
                height: 4,
                color: Color(0xFF207CCA),
                margin: EdgeInsets.only(top: 20),
              ),
            ],
          ),
        ),
        // 页面副标题
        Center(
          child: Container(
            width: 800,
            margin: EdgeInsets.symmetric(vertical: 20),
            child: Text(
              subtitle,
              style: TextStyle(
                color: Color(0xFF666666),
                fontSize: 18,
                height: 1.8,
              ),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ],
    );
  }
}

// lib/components/common_footer.dart

class CommonFooter extends StatelessWidget {
  final List<Map<String, String>> links;
  final String copyright;
  final String? contactInfo;

  const CommonFooter({
    super.key,
    required this.links,
    required this.copyright,
    this.contactInfo,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        color: Color(0xFF1a1a2e),
        borderRadius: BorderRadius.vertical(top: Radius.circular(8)),
      ),
      width: Get.width,
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(top: 50),
      child: Column(
        children: [
          Wrap(
            alignment: WrapAlignment.center,
            spacing: 20,
            runSpacing: 10,
            children: links
                .map((link) => InkWell(
                      onTap: () {
                        // 处理链接点击
                      },
                      child: Text(
                        link['name']!,
                        style: const TextStyle(
                          color: Color(0xFFa8b2d1),
                          fontSize: 14,
                        ),
                      ),
                    ))
                .toList(),
          ),
          const SizedBox(height: 20),
          Text(
            copyright,
            style: const TextStyle(
              color: Colors.white,
              fontSize: 14,
            ),
          ),
          if (contactInfo != null)
            Padding(
              padding: const EdgeInsets.only(top: 10),
              child: Text(
                contactInfo!,
                style: const TextStyle(
                  color: Colors.white70,
                  fontSize: 12,
                ),
              ),
            ),
        ],
      ),
    );
  }
}

class NewsFooter extends StatelessWidget {
  const NewsFooter({super.key});

  @override
  Widget build(BuildContext context) {
    return _buildFooter();
  }

  // 页脚
  Widget _buildFooter() {
    return Container(
      margin: const EdgeInsets.all(20),
      padding: const EdgeInsets.all(40),
      decoration: BoxDecoration(
        color: const Color(0xFF1A1A2E),
        borderRadius: BorderRadius.circular(8),
      ),
      width: Get.width,
      child: Column(
        children: [
          Wrap(
            spacing: 40,
            runSpacing: 20,
            alignment: WrapAlignment.center,
            children: [
              _footerLink('关于基地'),
              _footerLink('新闻动态'),
              _footerLink('入驻申请'),
              _footerLink('人才招聘'),
              _footerLink('联系我们'),
            ],
          ),
          const SizedBox(height: 20),
          const Text(
            '© 2025 濮阳人工智能创新应用示范基地 版权所有',
            style: TextStyle(
              color: Colors.white,
              fontSize: 14,
            ),
          ),
          const Text(
            '地址：河南省濮阳市高新技术开发区人工智能产业园 | 电话：0393-1234567 | 邮箱：info@puyang-ai.com',
            style: TextStyle(
              color: Colors.white,
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }

  // 页脚链接
  Widget _footerLink(String text) {
    return TextButton(
      onPressed: () {},
      style: TextButton.styleFrom(
        padding: EdgeInsets.zero,
        minimumSize: const Size(50, 30),
      ),
      child: Text(
        text,
        style: const TextStyle(
          color: Color(0xFFA8B2D1),
          fontSize: 16,
        ),
      ),
    );
  }
}

// 导航栏组件
class CustomNavbar extends StatefulWidget {
  final String currentRoute;
  const CustomNavbar({super.key, required this.currentRoute});

  @override
  State<CustomNavbar> createState() => _CustomNavbarState();
}

class _CustomNavbarState extends State<CustomNavbar> {
  final List<Map<String, dynamic>> _navItems = [
    {'title': '首页', 'route': '/'},
    {'title': '政策法规', 'route': '/policy'},
    {'title': '双创活动', 'route': '/activity'},
    {'title': '双创支撑', 'route': '/support'},
    {'title': '双创项目', 'route': '/project'},
    {'title': '双创资源', 'route': '/resource'},
    {'title': '双创载体', 'route': '/carrier'},
  ];

  void _onNavTap(String route) {
    if (route != widget.currentRoute) {
      Navigator.pushReplacementNamed(context, route);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFF1e3c72), Color(0xFF2a5298)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          stops: [0.0, 1.0],
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 10,
            offset: Offset(0, 2),
          )
        ],
      ),
      padding: const EdgeInsets.symmetric(horizontal: 20),
      child: Container(
        height: 70,
        constraints: const BoxConstraints(maxWidth: 1200),
        margin: const EdgeInsets.symmetric(horizontal: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            const Text(
              '城乡一体化示范区',
              style: TextStyle(
                color: Colors.white,
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
            Expanded(
              child: LayoutBuilder(
                builder: (context, constraints) {
                  return constraints.maxWidth > 768
                      ? _buildDesktopNav()
                      : _buildMobileNav();
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildDesktopNav() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: _navItems
          .map((item) => Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child: InkWell(
                  onTap: () => _onNavTap(item['route']),
                  borderRadius: BorderRadius.circular(5),
                  child: Container(
                    padding: const EdgeInsets.symmetric(
                        horizontal: 15, vertical: 10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(5),
                      color: widget.currentRoute == item['route']
                          ? Colors.white24
                          : Colors.transparent,
                    ),
                    child: Text(
                      item['title'],
                      style: const TextStyle(
                        color: Colors.white,
                        fontSize: 16,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ),
              ))
          .toList(),
    );
  }

  Widget _buildMobileNav() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: _navItems
          .map((item) => Padding(
                padding: const EdgeInsets.symmetric(horizontal: 5),
                child: InkWell(
                  onTap: () => _onNavTap(item['route']),
                  borderRadius: BorderRadius.circular(5),
                  child: Container(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(5),
                      color: widget.currentRoute == item['route']
                          ? Colors.white24
                          : Colors.transparent,
                    ),
                    child: Text(
                      item['title'],
                      style: const TextStyle(
                        color: Colors.white,
                        fontSize: 14,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ),
              ))
          .toList(),
    );
  }
}

// 页面标题组件
class PageHeader extends StatelessWidget {
  final String title;
  final String subtitle;
  final String description;

  const PageHeader({
    super.key,
    required this.title,
    required this.subtitle,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 60),
      padding: const EdgeInsets.symmetric(vertical: 40),
      width: double.infinity,
      decoration: BoxDecoration(
        gradient: const LinearGradient(
          colors: [Color(0xFFFFFFFF), Color(0xFFf0f8ff)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        borderRadius: BorderRadius.circular(15),
        boxShadow: const [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 20,
            offset: Offset(0, 5),
          )
        ],
      ),
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(bottom: 15),
            child: Text(
              title,
              style: const TextStyle(
                fontSize: 36,
                color: Color(0xFF1e3c72),
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(bottom: 20),
            child: Text(
              subtitle,
              style: const TextStyle(
                fontSize: 18,
                color: Color(0xFF666666),
              ),
            ),
          ),
          Container(
            constraints: const BoxConstraints(maxWidth: 800),
            padding: const EdgeInsets.symmetric(horizontal: 20),
            child: Text(
              description,
              style: const TextStyle(
                fontSize: 16,
                color: Color(0xFF555555),
                height: 1.8,
              ),
              textAlign: TextAlign.center,
            ),
          ),
        ],
      ),
    );
  }
}

// 内容区块组件
class ContentSection extends StatelessWidget {
  final String title;
  final String subtitle;
  final Widget content;
  final int animationIndex;

  const ContentSection({
    super.key,
    required this.title,
    required this.subtitle,
    required this.content,
    required this.animationIndex,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 60),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(15),
        boxShadow: const [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 20,
            offset: Offset(0, 5),
          )
        ],
      ),
      child: Column(
        children: [
          Container(
            padding: const EdgeInsets.symmetric(vertical: 25, horizontal: 30),
            width: Get.width,
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0xFF1e3c72), Color(0xFF2a5298)],
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
              ),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: const TextStyle(
                    fontSize: 24,
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  subtitle,
                  style: const TextStyle(
                    fontSize: 14,
                    color: Colors.white70,
                  ),
                ),
              ],
            ),
          ),
          Container(
            padding: const EdgeInsets.all(35),
            child: content,
          ),
        ],
      ),
    );
  }
}

// 特色功能项组件
class FeatureItem extends StatelessWidget {
  final String icon;
  final String title;
  final String description;

  const FeatureItem({
    super.key,
    required this.icon,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 300),
        padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
        decoration: BoxDecoration(
          gradient: const LinearGradient(
            colors: [Color(0xFFf8fbff), Color(0xFFf0f8ff)],
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
          ),
          borderRadius: BorderRadius.circular(12),
          border: Border.all(color: const Color(0xFFe1e8ed)),
        ),
        child: Column(
          children: [
            Text(
              icon,
              style: const TextStyle(
                fontSize: 40,
              ),
            ),
            SizedBox(
              height: 15,
            ),
            Text(
              title,
              style: const TextStyle(
                fontSize: 18,
                color: Color(0xFF1e3c72),
                fontWeight: FontWeight.bold,
              ),
            ),
            SizedBox(
              height: 10,
            ),
            Text(
              description,
              style: const TextStyle(
                fontSize: 14,
                color: Color(0xFF666666),
                height: 1.6,
              ),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }
}

// 内容区块组件
class ContentDoubleSection extends StatelessWidget {
  final String title;
  final String subtitle;
  final Widget content;

  ContentDoubleSection({
    required this.title,
    required this.subtitle,
    required this.content,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 60),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(15),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 20,
            offset: Offset(0, 5),
          ),
        ],
      ),
      child: Column(
        children: [
          // 区块标题
          Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0xFF1e3c72), Color(0xFF2a5298)],
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
              ),
            ),
            width: double.infinity,
            padding: EdgeInsets.symmetric(horizontal: 30, vertical: 25),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 24,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  subtitle,
                  style: TextStyle(
                    color: Colors.white70,
                    fontSize: 14,
                  ),
                ),
              ],
            ),
          ),
          // 底部装饰线
          Container(
            height: 3,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0xFF4facfe), Color(0xFF00f2fe)],
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
              ),
            ),
          ),
          // 区块内容
          Container(
            padding: EdgeInsets.all(35),
            child: content,
          ),
        ],
      ),
    );
  }
}
